﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

@using LeSoft.Application.Code;
<script>
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId", _state = 0, _pstructId = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
            }, 200);
            e.stopPropagation();
        });

        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree();
                    _pstructId = "";
                    SearchEvent();
                }
            }
        });
        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);

        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });

        //状态
        $("#State").ComboBox({
            data: [{ "key": 0, "value": "所有" }, { "key": 1, "value": "有效" }, { "key": 2, "value": "已经签约" }, { "key": 3, "value": "已取消" }],
            id: "key",
            text: "value",
            click: function (item) {
                if (_state != item.attr('data-value')) {
                    _state = item.attr('data-value');
                }
                SearchEvent();
            }
        });

        $("#State").ComboBoxSetValue(0);
    }

    function GetTree() {
        var item = {
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=5&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                if (item.id != _pstructId) {
                    _pstructId = item.id;
                    _organizeid = $("#PStructTree").attr("data-value");
                    SearchEvent();
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }


    function GetGrid() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        queryJson["State"] = _state;
        queryJson["EndDate"] = queryJson["EndDate"] + " 23:59:59";
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../QualificationManage/SelectRoomRecord/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "会员名称", name: "name", index: "name", width: 120, align: "center" },
                { label: "会员手机号", name: "phone", index: "phone", width: 120, align: "center" },
                { label: "会员编号", name: "membercode", index: "membercode", width: 200, align: "center" },
                { label: "房间名称", name: "roomallname", index: "roomallname", width: 300, align: "left" },
                { label: "合同编号", name: "contractcode", index: "contractcode", width: 180, align: "center" },
                 {
                     label: "状态", name: "state", index: "state", width: 100, align: "center",
                     formatter: function (cellvalue, options, rowObject) {

                         switch (cellvalue) {
                             case 1: return "有效"; break;
                             case 2: return "已经签约"; break;
                             case 3: return "已取消"; break;
                             default: return cellvalue; break;
                         }
                     }
                 },
                {
                    label: "选房日期", name: "choosetime", index: "choosetime", width: 140, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                }, 
                { label: "到期日期", name: "canceltime", index: "canceltime", width: 200, align: "center" }
            ],
            viewrecords: true,
            sortable: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'choosetime desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true
        });
        //查询点击事件
        $("#btn_Search").click(function () {
            SearchEvent();
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["EndDate"] = queryJson["EndDate"] + " 23:59:59"; 
        queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        queryJson["State"] = _state;
        queryJson["PstructId"] = _pstructId;
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../QualificationManage/SelectRoomRecord/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '新增',
            url: '/QualificationManage/SelectRoomRecord/Form',
            width: "1100px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //修改
    function btn_detail() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑',
                url: '/QualificationManage/SelectRoomRecord/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "750px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

</script>


<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height:97.5%;overflow-y: auto;">
            <div class="panel-Title" style="height:28px;padding-left:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table id="filter-form">
                        <tr>
                            <td style="padding-left: 2px;">
                                状态：
                            </td>
                            <td style="padding-left: 2px;">
                                <div id="State" type="selectTree" class="ui-select" style="width: 90px;"></div>
                            </td>
                            <td style="padding-left: 2px;">
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown" data-value="ChooseTime">选房时间</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="ChooseTime">选房时间</a></li>
                                        <li><a data-value="CancelTime">取消时间</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="BeginDate" type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({ maxDate: '#F{$dp.$D(\'EndDate\')}' })">
                            </td>
                            <td style="padding-left: 2px;">
                                至
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="EndDate" type="text" value="@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({ minDate: '#F{$dp.$D(\'BeginDate\')}'})">
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" maxlength="20" class="form-control" placeholder="请输入要查询的会员信息" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-detail" class="btn btn-default" onclick="btn_detail()"><i class="fa fa-eye"></i>&nbsp;编辑</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

